fix(routing): prevent dynamic static-suffix routes from shadowing static routes#6
fix(routing): prevent dynamic static-suffix routes from shadowing static routes#6JaredStowell wants to merge 1 commit intomainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c31379afbe
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (isDynamic && score <= 0) { | ||
| score = 1; |
There was a problem hiding this comment.
Avoid collapsing dynamic precedence scores
Clamping every dynamic route with score <= 0 to 1 removes the relative ordering between distinct dynamic patterns that were previously differentiated by infix static specificity. For example, /:a/x/y and /:a/x/:b now both score 1, so the router falls back to lexicographic order and can try /:a/x/:b first, incorrectly shadowing the more specific /:a/x/y on /foo/x/y. This regression is introduced by the new clamp because the prior scoring kept these routes distinct.
Useful? React with 👍 / 👎.
Motivation
/:id/settings) to score lower than fully static routes (e.g./users/settings), causing dynamic routes to be tried before static ones and shadow them.Description
1for any route detected as dynamic inroutePrecedence.0) always outrank any dynamic route./users/settings(static) outranks/:id/settings(dynamic with static suffix) by importing and exercisingroutePrecedenceintests/routing.test.ts.packages/vinext/src/routing/utils.tsandtests/routing.test.ts.Testing
pnpm vitest run tests/routing.test.ts, which completed and passed the routing tests including the new regression test.pnpm vitest run tests/routing.test.ts -t "keeps fully static routes ahead", which also passed and validates the specific case.Codex Task